﻿@{
    Layout = "~/Views/Shared/_Layout.cshtml";
    <script charset="utf-8" src="/resources/scripts/ajaxfileupload.js"></script>
}
@using AFT.Parking.Entity
@model MaterialRecord
<div class="content-box">
    <!-- Content box header -->
    <div class="content-box-header clearfix">
        <h3>添加机械设备信息</h3>
    </div>

    <!-- Content box body -->
    <div class="content-box-content">
        <div class="tab-content default-tab" id="tab2">
            <form class="material-form" method="post" id="frm">
                <fieldset>
                    <div class="x-tab-item">
                        @Html.Hidden("Id", Model.Id)
                        @Html.Hidden("TagId", Model.TagId)
                        @Html.Hidden("CreatorId",Model.CreatorId)
                        @Html.Hidden("CreateTime", Model.CreateTime)

                        <div class="upload-box">
                            <div class="upload-block">
                                <label>验收记录</label>
                                @{
                                    var img = string.IsNullOrEmpty(Model.InstallationCheckImg) ? "/resources/images/picture-model.png" : Model.InstallationCheckImg;
                                }
                                <div class="upload">
                                    <img style="width: 130px; height: 130px;" src="@img" />
                                    <input type="hidden" name="InstallationCheckImg" value="@Model.InstallationCheckImg" />
                                    <button type="button" class="button" id="checkBtn">上传验收记录</button>
                                </div>
                            </div>

                            <div class="upload-block">
                                <label>最新维保附件</label>
                                @{
                                    var checkImg = string.IsNullOrEmpty(Model.MaintenanceImg) ? "/resources/images/picture-model.png" : Model.MaintenanceImg;
                                }
                                <div class="upload">
                                    <img style="width: 130px; height: 130px;" src="@checkImg" />
                                    <input type="hidden" name="MaintenanceImg" value="@Model.MaintenanceImg" />
                                    <button type="button" class="button" id="maintainBtn">上传最新维保附件</button>
                                </div>
                            </div>
                        </div>

                        <div class="rt-content-box">
                            <p>
                                <label>设备名称</label>
                                @Html.TextBox("MaterialName", Model.MaterialName, new { @class = "text-input x-input-material" })
                            </p>
                            <p>
                                <label>二维码名称</label>
                                @if (Model.Id > 0)
                                {
                                    @Html.TextBox("TagName", Model.TagName, new { @class = "text-input  x-input-material", @readonly = "readonly", style = "background: #E4E4E4;cursor:not-allowed" })
                                }
                                else
                                {
                                    @Html.TextBox("TagName", Model.TagName, new { @class = "text-input x-input-material" })
                                }

                            </p>
                            <p>
                                <label>生产厂家</label>
                                @Html.TextBox("ProductionCompany", Model.ProductionCompany, new { @class = "text-input x-input-material" })
                            </p>
                        </div>


                        <p>
                            <label><span class="label-left x-company">安装厂家</span></label>
                            @Html.TextBox("InstallationCompany", Model.InstallationCompany, new {@class = "text-input x-company"})
                        </p>

                        <p>
                            <label><span class="label-left x-company-date">安装日期</span></label>
                            @Html.TextBox("InstallationDate", Model.InstallationDate, new { @class = "text-input x-company" })
                        </p>

                        <p>
                            <label><span class="label-left x-company">验收单位</span></label>
                            @Html.TextBox("CheckCompany", Model.CheckCompany, new {@class = "text-input x-company"})
                        </p>

                        <p>
                            <label><span class="label-left x-company-date">验收日期</span></label>
                            @Html.TextBox("CheckDate", Model.CheckDate, new { @class = "text-input x-company" })
                        </p>
                        <p>
                            <label>
                                <span class="label-left x-contacter">司机姓名</span>
                                <span class="label-left x-contact-num">司机联系方式</span>
                            </label>
                            <input type="text" name="DriverName" value="@Model.DriverName" class="text-input x-contacter" placeholder="联系人姓名"/>
                            <input type="text" name="DriverNum" value="@Model.DriverNum" class="text-input x-contact-num" placeholder="联系人电话"/>
                        </p>
                        <p>
                            <label>
                                <span class="label-left x-contacter">负责人</span>
                                <span class="label-left x-contact-num">负责人联系方式</span>
                            </label>
                            <input type="text" name="ResponsibleName" value="@Model.ResponsibleName" class="text-input x-contacter" placeholder="联系人姓名"/>
                            <input type="text" name="ResponsibleNum" value="@Model.ResponsibleNum" class="text-input x-contact-num" placeholder="联系人电话"/>
                        </p>
                    </div>
                </fieldset>
                <div class="x-btns">
                    <input class="button x-btn" type="submit" id="btnSubmit" value="&nbsp;保 存&nbsp;"/>
                    <input class="button x-btn" type="button" id="btnBack" value="&nbsp;返 回&nbsp;"/> <br/>
                    <span class="input-notification @ViewBag.Icon png_bg">@ViewBag.Message</span>
                    <input type="hidden" id="hd_backUrl" value="@Url.Action("MaterialRecordList")">
                </div>
            </form>
        </div>
    </div>
</div>

<script>
    new AjaxUpload($("#checkBtn"), {
        action: '@Url.Action("UpLoadFile")',
        data: { folderName: "MaterialFile"},
        name: 'UpLoadFile',
        responseType: "json",
        onSubmit: function (file, extension) {
        },
        onComplete: function (file, data) {
            console.log($(this).html());
            var btn = $(this._button);
            var fileImg = btn.siblings('img');
            var imgShow = btn.prev();
            console.log(fileImg, imgShow);
            if (data.Value) {
                fileImg.attr("src", data.Result[0]);
                imgShow.val(data.Result[0]);
            }
            else {
                alert("上传失败。");
            }
        }
    });

    new AjaxUpload($("#maintainBtn"), {
        action: '@Url.Action("UpLoadFile")',
        data: { folderName: "MaterialFile" },
        name: 'UpLoadFile',
        responseType: "json",
        onSubmit: function (file, extension) {
        },
        onComplete: function (file, data) {
            console.log($(this).html());
            var btn = $(this._button);
            var fileImg = btn.siblings('img');
            var imgShow = btn.prev();
            console.log(fileImg, imgShow);
            if (data.Value) {
                fileImg.attr("src", data.Result[0]);
                imgShow.val(data.Result[0]);
            }
            else {
                alert("上传失败。");
            }
        }
    });
</script>

<script type="text/javascript">
    $(function () {
        laydate({
            elem: '#InstallationDate'
        });
        laydate({
            elem: '#CheckDate'
        });
    });
</script>

